<template>
	<view class="company_join" v-if="showPop" @tap="layClickHandle" id="layer">
		<view class="content">
			<view class="search" v-if="!company.companyId">
				 <input_icon @input="inputKey" prefix="search" placeholder="编号/名称"/>
				 <view class="action" @tap="getCompany">查询</view>
			</view>
			<view class="result" v-if="company.companyId">
				 <view class="row">
					 <view class="label">编号/名称</view>
					 <view class="value">{{company.companyName}}</view>
				 </view>
				 <view class="row">
					 <view class="label">手机号</view>
					 <view class="value">{{company.userPhone}}</view>
				 </view>
				 <view class="row">
					 <view class="label">姓名</view>
					 <view class="value">{{company.userName}}</view>
				 </view>
				 <view class="row">
					 <view class="label">备注</view>
					 <view class="value">
						 <input class="remark" placeholder="请输入备注" @input="remarkInput"/>
					 </view>
				 </view>
				 <customButton classes="bigBt sure" @tap="submitApply">提交申请</customButton>
			</view>
		</view>
	</view>
</template>

<script>
	import input_icon from '@/common/components/input/input-icon/index.vue'
	import customButton from '@/common/components/button/index.vue'
	export default {
		components: {
			input_icon, customButton
		},
		data() {
			return {
				key: '',
				showPop: false,
				company: {},
				remark: ''
			}
		},
		props: {
			_showPop: {
				type: Boolean,
				default: false
			},
		},
		watch: {
			_showPop(newValue, oldValue) {
				this.showPop = true
			}
		},
		methods: {
			inputKey(e) {
				this.key = e.target.value
			},
			getCompany() {
				this.http.GET({
					name: 'getcompany',
					params: {
						codeOrName: this.key
					}
				})
				.then(res => {
					if(res.result === 'success') {
						this.company = res.data
					}
				})
			},
			layClickHandle(e) {
				if(e.target.id === 'layer') {
					this.showPop = false
					this.company = {}
					this.key = ''
				}
			},
			remarkInput(e) {
				this.remark = e.target.value
			},
			submitApply() {
				this.http.POST({
					name: 'applycompany',
					params: {
						companyId: this.company.companyId,
						description: this.remark
					}
				})
				.then(res => {
					if(res.result === 'success') {
						uni.showToast({
							title: '申请提交成功！',
							icon: 'none'
						})
						this.showPop = false
					}
				})
			}
		},
	}
</script>

<style>
	.company_join {
		position: fixed;
		top: 0upx;
		bottom: 0upx;
		left: 0upx;
		right: 0upx;
		background: rgba(0,0,0,0.6);
		padding: 0upx 24upx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.company_join .content {
		width: 100%;
		background-color: white;
		border-radius: 8upx;
	}
	.company_join .content .search {
		margin: 0upx 55upx;
		margin-top: 49upx;
		margin-bottom: 60upx;
		display: flex;
		justify-content: space-between;
		border: 1upx solid #DDDDDD;
	}
	.company_join .content .search .action {
		background: var(--theme-color);
		color: white;
		font-size: 32upx;
		width: 174upx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.company_join .content .search input_icon {
		flex: 1;
	}
	.company_join .content .search .wrapper {
		height: 100upx;
		border-bottom: none;
	}
	.company_join .content .search input_icon .icon {
		width: 28upx;
		height: 28upx;
	}
	.company_join .content .result {
		width: 100%;
		text-align: center;
	}
	.company_join .content .result .row {
		border-bottom: 1upx solid #DDDDDD;
		padding: 34upx 27upx;
		display: flex;
		justify-content: space-between;
	}
	.company_join .content .result .row .label {
		font-size: 28upx;
	}
	.company_join .content .result .row .value {
		font-size: 28upx;
		color: #666666;
	}
	.company_join .content .result input {
		text-align: right;
	}
	.company_join .content .result custom-button button{
		margin-top: 88upx;
		margin-bottom: 47upx;
		width: 553upx;
	}
</style>
